package com.itheima.demo;

import java.util.Random;

public class Test1 {
    public static void main(String[] args) {

        random1();
        random2();
    }

    //生成随机数的两种方法

    public static void random1() {
        //Math.random()生成[0,1)的随机小数
        int num = (int) (Math.random() * 100) + 1;   //[0,100) -> [1,101)即[1,100]
        System.out.println(num);
    }

    public static void random2() {
        //创建一个随机数对象
        Random r = new Random();
        int num = r.nextInt(100) + 1;   //[0,100) -> [1,101)即[1,100]
        System.out.println(num);
    }
}
